#pragma once
#include <list>
#include <string>
using namespace std;

//typedef string State;
class Subject;
class iObserver
{
public:
	virtual ~iObserver();
	virtual void Update(Subject* isub)=0;
	virtual void Display()=0;
protected:
	iObserver();

};
iObserver::iObserver()
{

}
iObserver::~iObserver()
{

}
class Subject
{
public:
	virtual ~Subject();
	virtual void Notify();
	virtual void addObserver(iObserver* ob);
	virtual void deleteObserver(iObserver* ob);
	virtual void SetState(const string& is)=0;
	virtual string GetState()=0;

protected:
	Subject();

private:
	list<iObserver*>* m_obList;
	//bool			 m_State;
	
};

Subject::Subject()
{
	m_obList = new list<iObserver*>;
	//m_State = false;
}
Subject::~Subject()
{
	delete m_obList;
}

void Subject::addObserver(iObserver *ob)
{
	if( m_obList )
		m_obList->push_front( ob );
}
void Subject::deleteObserver(iObserver* ob)
{
	if( m_obList )
		m_obList->remove( ob );
}

void Subject::Notify()
{
	list<iObserver*>::iterator it = m_obList->begin();
	while( it!= m_obList->end())
	{
		(*it)->Update( this );
		it++;
	}
}


